//
//  PaySuccessAlert.m
//  ImGuider
//
//  Created by 李陆涛 on 2018/6/28.
//  Copyright © 2018年 imguider. All rights reserved.
//

#import "PaySuccessAlert.h"

@interface PaySuccessAlert ()

@property (weak, nonatomic) IBOutlet NSLayoutConstraint *songViewTop;
@property (weak, nonatomic) IBOutlet UILabel *songLabel;

@property (weak, nonatomic) IBOutlet UILabel *coinLabel;
@property (weak, nonatomic) IBOutlet UIButton *okBtn;

@property (nonatomic, strong) void (^ dissmissBlock)(void);

@end

@implementation PaySuccessAlert

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = [UIColor colorWithWhite:0 alpha:0.6];
    
    self.songViewTop.constant = kScreenWidth;
    
    self.songLabel.text = @"";
    self.coinLabel.text = @"";
}


//- (void)setDict:(NSDictionary *)dict {
//
//    _dict = dict;
//
//    [self setupUI];
//}

- (void)setupUI {
    
    NSInteger song = [self.dict[@"song"] integerValue];
    NSInteger yue = [self.dict[@"yue"] integerValue];
    
    NSMutableAttributedString *text1 = [[NSMutableAttributedString alloc] initWithString:@"您已成功领取"];
    text1.font = Font(20);
    text1.color = [UIColor blackColor];
    NSMutableAttributedString *text2 = [[NSMutableAttributedString alloc] initWithString:@(song).stringValue];
    text2.font = FontBold(32);
    text2.color = kThemeYellowColor;
    NSMutableAttributedString *text3 = [[NSMutableAttributedString alloc] initWithString:@"G币"];
    text3.font = Font(20);
    text3.color = [UIColor blackColor];
    
    NSMutableAttributedString *text = [[NSMutableAttributedString alloc] initWithAttributedString:text1];
    [text appendAttributedString:text2];
    [text appendAttributedString:text3];
    
    self.songLabel.attributedText = text;
    
    self.coinLabel.text = [NSString stringWithFormat:@"当前余额：%ldG币",(long)yue];
}

- (IBAction)okAction:(id)sender {
    
    [self hiddenVC];
}

- (void)showWithVC:(UIViewController *)vc block:(void(^)(void))dissmissBlock {
    self.dissmissBlock = dissmissBlock;
    self.modalPresentationStyle = UIModalPresentationOverFullScreen;
    
    @weakify(self);
    [vc presentViewController:self animated:NO completion:^{
        @strongify(self);
        [self setupUI];
        self.songViewTop.constant = kScreenWidth / 3;
        [UIView animateWithDuration:0.5 animations:^{
            
            [self.view layoutIfNeeded];
        }];
    }];
    
    
}

- (void)hiddenVC {
    
    self.songViewTop.constant = kScreenWidth;
    
    @weakify(self);
    [UIView animateWithDuration:0.5 animations:^{
        @strongify(self);
        [self.view layoutIfNeeded];
    } completion:^(BOOL finished) {
        @strongify(self);
        [self dismissViewControllerAnimated:NO completion:^{
            
            if (self.dissmissBlock) {
                self.dissmissBlock();
            }
        }];
    }];
    
    
}

@end
